<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .child1 {
            width: 300px;
            height: 300px;
            background: red;
        }
        .child2 {
            width: 200px;
            height: 200px;
            background: blue;
        }
        .child3 {
            width: 100px;
            height: 100px;
            background: yellow;
        }
    </style>
</head>
<body>
    <!-- 事件冒泡 -->

    <div class="child1">
        <div class="child2">
            <div class="child3"></div>
        </div>
    </div>

    <a href="http://www.baidu.com" target="_blank">跳转百度</a>

    <script>
        // 点击事件
        // 事件捕获 --- 鼠标点到谁,那么最先捕获谁
        // 事件触发 --- 捕获到的目标对象最先触发
        // 事件冒泡 --- 自捕获到的第一个目标开始,逐级向上,直至没有父节点,冒泡停止

        document.querySelector('.child1').onclick = function (event) {
            // console.log(event.target)
            alert('child1被触发了')
        }
        document.querySelector('.child2').onclick = function (event) {
            // console.log(event.target)
            alert('child2被触发了')
        }
        document.querySelector('.child3').onclick = function (event) {
            // 阻止事件冒泡
            event.stopPropagation()
            console.log(event)
            alert('child3被触发了')
        }

        document.querySelector('a').onclick = function (event) {
            // 阻止事件的默认行为
            event.preventDefault()

            window.open('http://www.baidu.com', 'myWindow')
            console.log(event)
        }

    </script>
</body>
</html>